package com.grao.waterschool.human.common;

import java.io.Serializable;

public class R<T> implements Serializable {

    private final Integer status;
    private final String msg;
    private final T data;

    private R(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
        this.data = null;
    }

    private R(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <T> R<T> success() {
        return success(0, "success");
    }

    public static <T> R<T> success(String msg) {
        return success(0, msg);
    }

    public static <T> R<T> success(int status, String msg) {
        return new R(status, msg);
    }

    public static <T> R<T> success(T data) {
        return success(0, "success", data);
    }

    public static <T> R<T> success(String msg, T data) {
        return success(0, msg, data);
    }

    public static <T> R<T> success(int status, String msg, T data) {
        return new R(status, msg, data);
    }

    public static <T> R<T> error(String msg) {
        return error(500, msg);
    }

    public static <T> R<T> error(int status, String msg) {
        return of(status, msg);
    }

    public static <T> R<T> error(String msg, T data) {
        return success(500, msg, data);
    }

    public static <T> R<T> of(int status, String msg) {
        return of(status, msg, null);
    }

    public static <T> R<T> of(int status, String msg, T data) {
        return new R(status, msg, data);
    }

    public Integer getStatus() {
        return this.status;
    }

    public String getMsg() {
        return this.msg;
    }

    public Object getData() {
        return this.data;
    }
}
